package com.itheima03.day15Test;

/**
 * @author 刘全
 * @date 2021/8/9
 */
public class Foodie extends Thread {

    @Override
    public void run() {
        while (true) {
            synchronized (Desk.obj) {
                if (Desk.count == 0) {
                    break;
                } else {
                    try {
                        //判断桌子上有没有汉堡,有则吃汉堡,没有等厨师做汉堡
                        if (Desk.flag == true) {
                            //吃汉堡用了3秒
                            Thread.sleep(3000);
                            System.out.println("吃货吃完了汉堡");
                            Desk.count--;
                            Desk.flag = false;
                            Desk.obj.notify();
                        } else {
                            Desk.obj.wait();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

